// import  { a, add } from './d.js'
// 组合继承
function Parent(name) {
    this.name = name
}
Parent.prototype.getName = function () {
    return this.name
}

function Child() {
    Parent.call(this, 'child')
}
Child.prototype = new Parent()

const child = new Child(1)
console.log(child)





var { a, add } = require('./a.js')
console.log(a) // 1
add()
var c = require('./a.js')
console.log(a) // 1
// console.log(a)
// add()
// console.log(a)
console.log({} instanceof Object)


function *foo(x) {
    let y = 2 * (yield (x + 1))
    let z = yield (y / 3)
    return (x + y + z)
  }
  let it = foo(5)
  console.log(it)
  console.log(it.next())   // => {value: 6, done: false}
  console.log(it.next(12)) // => {value: 8, done: false}
  console.log(it.next(13)) // => {value: 42, done: true}


  console.log('script start')
  async function async1() {
    await async2()
    console.log('async1 end')
  }
  async function async2() {
    console.log('async2 end')
  }
  async1()
  
  setTimeout(function() {
    console.log('setTimeout')
  }, 0)
  
  new Promise(resolve => {
    console.log('Promise')
    resolve()
  })
    .then(function() {
      console.log('promise1')
    })
  process.nextTick(() => {
    console.log('nextTick...')
  })
  queueMicrotask(()=> {
    console.log('queueMicrotask....')
  })
  console.log('script end')



  function createObj(con, ...args) {
    const obj = { }
    obj.__proto__ = con.prototype
    const ret = con.call(obj, ...args)
    return ret && ret instanceof Object ? ret : obj
}
function Person(name) {
    this.name = name
    // return { a: 1 }
}
console.log(createObj(Person, 'zhangsan'), createObj(Person, 'zhangsan') instanceof Person)

const xMLHttp = new XMLHttpRequest();
xMLHttp.onreadystatechange = console.log
xMLHttp.open('GET', 'https://www.baidu.com',true);
xMLHttp.send();
